<template>
	<view>
		<u-toast ref="uToast" />
		<view class="photo_switch box box-align-center box-pack-between">
			<view class="box box-align-center">
				<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/photo.png" mode="widthFix" style="width: 60rpx;padding-right: 10rpx;"></image>
				<view>拍照搜题功能</view>
			</view>
			<view class="">
				<u-switch v-model="photoChecked" active-color="#5993ff" inactive-color="#e3e3e3" @change="geteditSetting"></u-switch>
			</view>
		</view>
		<view class="mar_top pad_big">
			<view class="txt">
				响应国家教育部相关规定，不向学生提供及推荐拍照搜题相关功能。
			</view>
			<view class="txt">
				注：若家长有需求使用该功能请谨慎开启。
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSetting,
		editSetting
	} from '@/api/systemControl.js'
	export default {
		data() {
			return {
				photoChecked:false,
				id:0
			};
		},
		onLoad() {
			this.getSettings(uni.getStorageSync('snId'))
		},
		methods:{
			getSettings(id){
				getSetting({
					id: id
				}).then(res => {
					let data = res.data
					this.id = data.id
					this.photoChecked = Boolean(data.search_topic)
				}).catch(err => {})
			},
			geteditSetting(value){
				let data = {
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
					id: this.id,
					type: 16,
					search_topic: Number(value)
				}
				console.log('参数', data)
				editSetting(data).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						icon: false,
						type: 'success'
					})
					this.getSettings(uni.getStorageSync('snId'))
				}).catch(err => {
					this.getSettings(uni.getStorageSync('snId'))
					this.$refs.uToast.show({
						title: err.msg,
						icon: false,
						type: 'error'
					})
				})
			}
		}
	}
</script>

<style lang="scss">
.photo_switch{
	border-radius: 20rpx;
	padding: 50rpx 20rpx;
	margin: 20rpx;
	background-color: #fff;
}
.txt{
	font-size: 24rpx;
	color: #afb1b2;
}
</style>
